﻿using QuanLyGiaoVuService.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;

namespace QuanLyGiaoVuService.CommonServices
{
    public class EmailService
    {
        private static EmailService Instance;

        private EmailService()
        {
 
        }

        public static EmailService GetInstance()
        {
            if (Instance == null)
            {
                Instance = new EmailService();
            }
            return Instance;
        }

        public bool SendEmail(EmailModel emailModel)
        {
            try
            {
                MailMessage mailMessage = new MailMessage();
                mailMessage.From = new MailAddress("gentlerain2408@gmail.com");
                foreach (String emailAddr in emailModel.DiaChiNguoiNhan)
                {
                    mailMessage.To.Add(new MailAddress(emailAddr));
                }
                mailMessage.Subject = emailModel.TieuDe;
                mailMessage.IsBodyHtml = false;
                mailMessage.Body = emailModel.NoiDung;

                var client = new SmtpClient();
                client.Host = "smtp.gmail.com";
                client.Port = 587;
                client.Credentials = new NetworkCredential("tamkimen@gmail.com", "");
                client.EnableSsl = true;
                //client.Send(mailMessage);
            }
            catch (Exception exception)
            {
                return false;
            }
            return true;
        }



    }
}
